package com.hxx.widget.richtext.views

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.View.OnClickListener
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView
import com.hxx.widget.R
import com.hxx.widget.richtext.RichEditor

/**
 * 富文本编辑器视图组件总容器
 */
class RichEditorView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr){
    private val TAG = "编辑器视图"
    private val showSoftWindow = OnClickListener {
        Log.i(TAG, "无响应事件:弹出软键盘 ")
    }
    private val adapter = RichEditorContentAdapter()

    fun getEditor(): RichEditor {
        return adapter
    }

    init {
        LayoutInflater.from(context).inflate(R.layout.widget_layout_rich_container, this, true)
            .apply {
                val recyclerView = findViewById<RecyclerView>(R.id.widget_rich_list)
                recyclerView.adapter = adapter
                val focusView = findViewById<View>(R.id.widget_rich_focus_view)
                focusView.setOnClickListener(showSoftWindow)
            }
    }

}